package com.qwiki.xml;

public class PageMultiHandler<T, S extends PageFilter<T>> implements PageHandler<T, S> {

  PageHandler<T, S>[] handlers;
  private int count;
  private S filter;

  public PageMultiHandler(PageHandler<T, S>[] handlers) {
    this.handlers = handlers;
  }

  @Override
  public synchronized boolean process(T page) {
    if (filter == null || filter.isGood(page))
      handlers[count++ % handlers.length].process(page);
    return true;
  }

  @Override
  public synchronized S getFilter() {
    // TODO Auto-generated method stub
    return filter;
  }

  @Override
  public synchronized void setFilter(S filter) {
    this.filter = filter;
  }

}
